﻿Imports System.Data.SqlClient

Public Class 期初设置


    Private Sub 退出btn_Click(sender As Object, e As EventArgs) Handles 退出btn.Click
        Me.Close()
    End Sub

    Private Sub 保存btn_Click(sender As Object, e As EventArgs) Handles 保存btn.Click
        ' 1️⃣ 获取金额
        Dim qcje As Decimal = 期初金额_data.Value

        ' 2️⃣ 基础验证
        If qcje <= 0 Then
            MessageBox.Show("请输入大于 0 的期初金额。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return
        End If

        ' 3️⃣ 执行存储过程
        Try
            Using conn As New SqlConnection(DbConnectionHelper.GetConnectString)
                conn.Open()

                Using cmd As New SqlCommand("usp_SetQC", conn)
                    cmd.CommandType = CommandType.StoredProcedure

                    ' 传入参数
                    cmd.Parameters.AddWithValue("@je", qcje)

                    ' 执行并读取返回信息
                    Dim result As Object = cmd.ExecuteScalar()

                    ' 如果存储过程返回SELECT信息
                    If result IsNot Nothing Then
                        LogHelper.WriteLog("执行期初设置：" & result.ToString())
                        MessageBox.Show(result.ToString(), "结果", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    Else
                        MessageBox.Show("执行完成。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    End If
                End Using
            End Using

        Catch ex As Exception
            LogHelper.WriteLog("执行出错：" & ex.Message)
            MessageBox.Show("执行出错：" & ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try
    End Sub

    Private Sub 期初设置_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' 默认值或初始化逻辑
        期初金额_data.DecimalPlaces = 2     ' 保留两位小数
        期初金额_data.Maximum = 1000000000   ' 最大值防止溢出
        期初金额_data.Value = 0
    End Sub

End Class
